package com.atguigu.functioncodeagain

 object WordCountTest {
   def main(args: Array[String]): Unit = {
     val list = List("Hbase Kafka","Scala Hbase", "Hello Scala", "Hello")
     list.flatMap(_.split(" ")).groupBy(x=>x).map(x=>(x._1,x._2.length)).foreach(println)

     val list1 = list.flatMap(_.split(" "))
     val map = list1.groupBy(x => x)
     val map1 = map.map(x => (x._1, x._2.length))
     map1.foreach(println)

     println("----------------------------")
     val tupleList = List( ("Hello Scala Spark World", 4) , ("Hello Scala Spark", 3), ("Hello Scala", 2), ("Hello", 1))
    tupleList.flatMap(x=>x._1.split(" ").map((_,x._2))).groupBy(_._1).map(x=>(x._1,x._2.map(_._2).sum)).foreach(println)
   }

 }

